// example_text_file_writer.cpp : Defines the entry point for the console application.
//

/*
// Sync Routine

#include "stdafx.h"
#include <Inklude/ikCUdpClient.h>
#include <Windows.h>

using namespace Inklude;
static const int MSG_SIZE = 300;
int _tmain(int argc, _TCHAR* argv[])
{   
    ikCUdpClient udpClient;
    udpClient.Initialize(5555);
    udpClient.SetDestinationAddress("127.0.0.1", 15575);
    char* buf = new char[MSG_SIZE];

    int count = 0;
    
    while (true)
    {
        count++;
		sprintf(buf, "this is %d\n", count);
        if (MSG_SIZE == udpClient.Send(buf, MSG_SIZE))
        {
            printf(buf);
        }

        Sleep(10);
    }
    
	return 0;
}


*/

// ASync Routine

#include "stdafx.h"
#include <Inklude/ikCUdpClient.h>
#include <Inklude/ikCMutex.h>
#include <time.h>
#include <Windows.h>

using namespace Inklude;
static const int MSG_SIZE = 60000;

int _tmain(int argc, _TCHAR* argv[])
{   
    ikCUdpClient udpClient;
    udpClient.Initialize(5555);
    udpClient.SetDestinationAddress("127.0.0.1", 15575);
    char* buf = new char[MSG_SIZE];

    srand ( time(NULL) );

    ikCMutex mutex;

    int count = 0;
    ikCUdpClient::AsyncHandler sendComplete;
    sendComplete.reset(new std::function<void(size_t)>([&](size_t param)
    {
        int dataSize = rand() % 50000;
        dataSize += 300;
        memcpy_s(buf, 4, &dataSize, 4);
        sprintf(buf + 4, "this is %d\n", dataSize);
        printf(buf + 4);
        udpClient.AsyncSend(buf, dataSize, sendComplete);
    }
    ));

    count++;

    int dataSize = rand() % 50000;
    dataSize += 300;
    memcpy_s(buf, 4, &dataSize, 4);
    sprintf(buf + 4, "this is %d\n", count);
    udpClient.AsyncSend(buf, dataSize, sendComplete);

    
    while (true)
    {
        Sleep(100);
    }
    
	return 0;
}
